package com.effectivsocial.domain;

import java.io.Serializable;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import lombok.Getter;
import lombok.Setter;

import org.hibernate.envers.Audited;
import org.hibernate.envers.NotAudited;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
import com.thoughtworks.xstream.annotations.XStreamImplicit;

@XStreamAlias("definition")
@Entity
@Table(name = "t_view_definition")
@Audited
public class ViewDefinition implements Serializable {

	private static final long serialVersionUID = 1L;
		
	@XStreamAsAttribute
	@Id
	@Getter @Setter
	@Column(name = "name", length=255, unique = true)
	private String name;
	
	@XStreamAsAttribute
	@Getter @Setter
	@Column(name = "preparer", length=1000)
	private String preparer;
	
	
	@XStreamAsAttribute
	@Getter @Setter
	@Column(name = "template", length=1000)
	private String template;
	
	@XStreamAsAttribute
	@Getter @Setter
	@Column(name = "parent_name")
	private String parent;
	
	@XStreamImplicit(itemFieldName="put-attribute")
	@Getter @Setter
	@Transient
	/*
	@NotAudited
	
	@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    @JoinTable(name = "t_definition_attribute", joinColumns = { @JoinColumn(name = "definition_id") }, 
    	inverseJoinColumns = { @JoinColumn(name = "attribute_id") })
    */
    private List<ViewAttribute> attributes;
	
	@NotAudited
	@Getter @Setter
	@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	@org.hibernate.annotations.Fetch(org.hibernate.annotations.FetchMode.SUBSELECT)
	@JoinTable(name = "t_link_group_view", joinColumns = { @JoinColumn(name = "link_group_id") }, inverseJoinColumns = { @JoinColumn(name = "view_id") })
    private List<LinkGroup> linkGroups;
	
}
